/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.Bl;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.Enumerations.TransactionStatus;
import mx.itsc.ds2.Dao.UserDaoLocal;
import mx.itsc.ds2.model.User;

/**
 *
 * @author Martinez
 */
@Stateless
public class UserBL implements UserBLLocal {

    @EJB
    private UserDaoLocal userDao;

    @Override
    public TransactionStatus register(User user) {
        if (userDao.findByDuplicity(user)) {
            return TransactionStatus.INCOMPLETO;
        } else {
            userDao.create(user);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus modify(User user) {
        if (userDao.find(user.getId()) == null || user.getId() == null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            userDao.edit(user);
            return TransactionStatus.COMPLETO;
        }

    }
    
    @Override
    public TransactionStatus remove(User user) {
        if (user.getId() == null || userDao.find(user.getId())== null) {
            return TransactionStatus.INCOMPLETO;
        }else{
            userDao.remove(user);
            return TransactionStatus.COMPLETO;
        }
        
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public List<User> findByUser(User user) {
        List<User> userList = userDao.findByUser(user);
        List<User> finalUserList = new ArrayList<User>();
        for (User user1 : userList) {
            finalUserList.add(user1);
        }
        return finalUserList;
    }

    
}
